package com.qire.manhua.activity;

import android.os.Bundle;

import com.qire.antscore.annotation.RouteMapping;
import com.qire.antsrouter.inject.Autowired;
import com.qire.common.constant.Navigation;
import com.qire.common.inject.EventControllerInjector;
import com.qire.common.inject.ViewModelInjector;
import com.qire.common.support.base.BaseActivity;
import com.qire.manhua.R;
import com.qire.manhua.controller.ComicDetailController;
import com.qire.manhua.databinding.ActivityComicDetailBinding;
import com.qire.manhua.model.viewModel.impl.ComicDetailViewModel;

import androidx.annotation.Nullable;

@RouteMapping(path = Navigation.Page.ComicDetailPage)
public class ComicDetailActivity extends BaseActivity<ActivityComicDetailBinding> {

    @Autowired
    int comicBookId;

    @Autowired
    int pageNo = 0;

    @Autowired(injector = EventControllerInjector.class)
    ComicDetailController controller;

    @Autowired(injector = ViewModelInjector.class)
    ComicDetailViewModel viewModel;

    boolean isFirst = true;

    @Override
    public int layoutRid() {
        return R.layout.activity_comic_detail;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        controller.onAddition(viewModel);
        viewModel.onAddition(this);
        viewModel.gotoTabPage(pageNo);
        viewModel.loadDetailInfo(comicBookId);
    }

    @Override
    protected void onResume() {
        super.onResume();
        viewModel.refreshFavoriteBtnUI();
        if(!isFirst) {
            viewModel.loadDirectoryInfo();
        }
        isFirst = false;
    }
}
